﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Kiva7.Controls
{
    public class BaseUserControl : UserControl
    {
        protected Page Page
        {
            get
            {
                return GetDependencyObjectFromVisualTree(this, typeof(Page)) as Page;
            }
        }

        protected DependencyObject GetDependencyObjectFromVisualTree(DependencyObject startObject, Type type)
        {
            DependencyObject parent = startObject;
            while (parent != null)
            {
                if (type.IsInstanceOfType(parent))
                    return parent;
                parent = VisualTreeHelper.GetParent(parent);
            }
            return null;
        }

        protected void DoNavigate(Uri uri)
        {
            BasePhoneApplicationPage basePage = Page as BasePhoneApplicationPage;
            if (basePage != null)
            {
                basePage.DoNavigate(uri);
            }
        }
    }
}
